import BadRoomStepView from "./BadRoomStepView";
import { EventName, ActionType } from "../../../public/Config";
import GlobalEvent from "../../../cfw/event/GlobalEvent";
import BadRoomManager from "../model/BadRoomManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class BadRoomStepView2 extends BadRoomStepView {

    @property([cc.Node])
    items: cc.Node[] = []


    start() {
        this.model = BadRoomManager.instance();
        this.node.active = true;
        cc.tween(this).by(2, {}).call(this.fly.bind(this)).start()
    }

    fly() {
        let size = cc.view.getVisibleSize();
        let w = size.width / 2
        let h = size.height / 2;
        for (let index = 0; index < this.items.length; index++) {
            const element = this.items[index];
            switch (index) {
                case 0://左下
                    cc.tween(element).by(1, { x: -w, y: -h }).to(0.2, { opacity: 0 }).start();
                    break;
                case 1:// 左
                    cc.tween(element).by(1, { x: -w, y: 0 }).to(0.2, { opacity: 0 }).start();
                    break;
                case 2://左上
                    cc.tween(element).by(1, { x: -w, y: h }).to(0.2, { opacity: 0 }).start();
                    break;
                case 3://右上
                    cc.tween(element).by(1, { x: w, y: h }).to(0.2, { opacity: 0 }).start();
                    break;
                case 4://右
                    cc.tween(element).by(1, { x: w, y: 0 }).to(0.2, { opacity: 0 }).start();
                    break;
                case 5://右下
                    cc.tween(element).by(1, { x: w, y: -h }).to(0.2, { opacity: 0 }).start();
                    break;

            }
        }
        GlobalEvent.instance().emit(EventName.CHANGE_PLAYER_ACTION,ActionType.AWAKE)
        cc.tween(this).by(1, {}).call(this.finish.bind(this)).start()
    }

    finish() {
        cc.log('this.node ', this.node)
        this.model.updateExp()
        GlobalEvent.instance().emit(EventName.UPDATE_SLEEP_STEP, 2)
    }

    // update (dt) {}
}
